//
//  DWDTabBar.m
//  dwdWbOc
//
//  Created by Dengdwd on 15/10/9.
//  Copyright © 2015年 dwd. All rights reserved.
//

#import "DWDTabBar.h"

@interface DWDTabBar ()
@property (nonatomic,strong) UIButton * btn;
@end

@implementation DWDTabBar
- (UIButton *)btn {
    if (!_btn) {
        _btn = [[UIButton alloc]init];
        [_btn addTarget:self action:@selector(btnDidClick) forControlEvents:UIControlEventTouchUpInside];
        [_btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];
        [_btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateSelected];
        [self addSubview:_btn];
    }
    return _btn;
}

- (void)btnDidClick {
    if (self.plusBlock) {
        self.plusBlock();
    }
}
- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat w = [UIScreen mainScreen].bounds.size.width / 5;
    CGFloat h = self.bounds.size.height;
    CGFloat x = 0;
    CGFloat y = 0;
    int index = 0;
    for (UIView * view in self.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")] && ![view isKindOfClass:[UIButton class]]) {
            
            view.frame = CGRectMake(x + (w * index), y, w, h);
            if (index == 1) {
                index += 1;
            }
            index++;
        }
    }
    self.btn.frame = CGRectMake(w * 2, 0, w, h);
    
}

@end
